from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
from Crypto.Signature import PKCS1_v1_5 as Signature_pkcs1_v1_5
import base64


def rsa_encrypt(password:str,publickey):
    """校验RSA加密 使用公钥进行加密"""
    public_key = '-----BEGIN PUBLIC KEY-----\n'+ publickey +'\n-----END PUBLIC KEY-----'
    cipher = Cipher_pkcs1_v1_5.new(RSA.importKey(public_key))
    cipher_text = base64.b64encode(cipher.encrypt(password.encode())).decode()
    return cipher_text